package com.qcby.byc.demo0422.controller;

import com.qcby.byc.demo0422.entity.Depart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.beans.PropertyEditorSupport;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @className: Demo0425Controller
 * @description:
 * @author: lxt
 * @create: 2021-04-25 14:29
 **/
@Controller
@RequestMapping("demo0425")
public class Demo0425Controller {


    protected Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("add")
    @ResponseBody
    public Depart addDemo(Depart depart){
        System.out.println("depart:"+depart);
        return depart;
    }




    public static void main(String[] args) {
        // 旧的（jdk7以及低于jdk7版本的）时间api里面的日期类型
        Date now = new Date();
        System.out.println(now);

        // jdk1.8时候  新的时间api
        System.out.println(LocalDate.now());
        // 创建时间 修改时间
        System.out.println(LocalDateTime.now());
        //  第几节课开始或者结束时间
        System.out.println(LocalTime.now());


        //  时间格式化
        // 要求输出  2020-20-02 10:10:10
        /**
         *
         */
        System.out.println("****************0528**********************");
        Date dateNow = new Date();
        System.out.println(dateNow);

        String pattern = "yyyy-MM-dd";
        DateFormat dateFormat1 = new SimpleDateFormat(pattern);
//        Date date = new Date(2021,5,27);
        // 时间日期类型
        Date date = null;
        try {
            String dateStr = "2021-05-27";
            //  将Sting类型的 时间字符串  解析转化成  Date类型
            date = dateFormat1.parse(dateStr);
            System.out.println("2021-05-27:"+date);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        String strDateFormat1 = "yyyy-MM-dd HH:mm:ss";
//        String strDateFormat1 = "yyyy/MM/dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat1);
        // 按照指定模板 格式化Date类型为String类型
        System.out.println("date-format："+sdf.format(date));

        LocalDate localDate = LocalDate.of(2021,5,27);

        System.out.println("【新-2021-05-27】:"+localDate);
        // 格式化
        String localDateFormat = "yyyy/MM/dd";
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(localDateFormat);
        String localDateStr = localDate.format(dateTimeFormatter);
        System.out.println("【新-2021-05-27-format】:"+localDateStr);

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDateTime:"+localDateTime);
        String strDateFormat = "yyyy-MM-dd HH:mm:ss";
        System.out.println("localDateTime-format:"+localDateTime.format(DateTimeFormatter.ofPattern(strDateFormat)));
        System.out.println("****************0528**********************");
        System.out.println("===============================");
        System.out.println(localDateTime.getYear());
        System.out.println(localDateTime.getMonth());
        System.out.println(localDateTime.getDayOfWeek());
        System.out.println(localDateTime.plusDays(5));
        System.out.println(localDateTime.plusDays(-5));
        System.out.println(localDateTime.plusMonths(3));
        System.out.println(localDateTime.plusYears(2));
        System.out.println("===============================");
        // 比较时间  时间1.isBefore(时间2) ？ =>  true  或者 false
        System.out.println(localDateTime.plusYears(-2).isBefore(localDateTime));
        System.out.println(localDateTime.plusYears(2).isBefore(localDateTime));

    }

}
